/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.core.sso;

import java.util.HashMap;
import java.util.Map;

import com.jinhe.tss.core.util.BeanUtil;

/** 
 * <p> UserIdentifierFactory.java </p> 
 * 
 */
public class UserIdentifierFactory {

    private static UserIdentifierFactory factory = null;

    private static Map<String, IUserIdentifier> cache = new HashMap<String, IUserIdentifier>();

    private UserIdentifierFactory() { }

    /**
     * 获取认证类
     * @return
     */
    public IUserIdentifier getUserIdentifier(String className) {
        IUserIdentifier identifier = (IUserIdentifier) cache.get(className);
        if (identifier == null) {
            cache.put(className, identifier = (IUserIdentifier) BeanUtil.newInstanceByName(className));
        }
        return identifier;
    }

    /**
     * 实例化认证类工厂本身
     * @return
     */
    public static UserIdentifierFactory instance() {
        if (factory == null) {
            factory = new UserIdentifierFactory();
        }
        return factory;
    }
}
